﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WorkerService1
{

    /// <summary>
    /// 保证进程中对象只被实例化一次，并且常驻内存，
    /// </summary>
    public class Singleton
    {
        private static readonly object _lock = new object();
        public static Singleton singleton { get; set; }
        static Singleton()
        {
            if (singleton == null)
            {
                lock (_lock)
                {
                    if (singleton == null)
                    {

                        singleton = new Singleton();
                    }
                }

            }
        }
        private Singleton()
        { }
    }
    class Singletontwo
    {
        private static readonly Object _lock = new object();
        public static Singletontwo singletontwo { get; set; }
        private Singletontwo()
        { }
        public static Singletontwo CreateSingleton()
        {
            if (singletontwo == null)
            {
                lock (_lock)
                {
                    if (singletontwo == null)
                    {

                        singletontwo = new Singletontwo();
                    }
                }

            }
            return singletontwo;
        }
    }
    class Singletonthe
    {
        public static Singletonthe sin = new Singletonthe();
    }
}
